from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
from app01.models import DeviceData


# 不适应于windows平台，暂时不使用了
def push_data_to_frontend():
    print("到这里了")
    channel_layer = get_channel_layer()
    data = list(DeviceData.objects.last())
    async_to_sync(channel_layer.group_send)(
        'myapp_group',
        {
            'type': 'data_message',
            'data': data
        }
    )
